package cn.xiuxian.service.impl;

import cn.xiuxian.dao.IVideoDao2;
import cn.xiuxian.dao.impl.VideoDaoImpl2;
import cn.xiuxian.model.dto.PageInfo;
import cn.xiuxian.model.pojo.Video;
import cn.xiuxian.service.IVideoService;

import java.util.List;

public class VideoServiceImpl  implements IVideoService {

    private IVideoDao2 videoDao2 = new VideoDaoImpl2();

    @Override
    public PageInfo<Video> findPage(String title, Integer pageNum, Integer pageSize) {

        PageInfo<Video>  pageInfo = new PageInfo<>();

        if(null ==title || title.trim().length()==0){
            title = "";
        }

        pageNum = pageNum ==null?1:pageNum;
        pageSize = pageSize ==null?3:pageSize;

        List<Video> videoList = videoDao2.findPage(title, pageNum, pageSize);

        pageInfo.setVideoList(videoList);

        pageInfo.setPageNum(pageNum);
        pageInfo.setPageSize(pageSize);

        Integer rows = videoDao2.findcount(title);

        pageInfo.setRows(rows);

        Integer  pageTotal = rows/pageSize;

        if(rows%pageSize!=0){
            pageTotal ++;
        }
        pageInfo.setPagetotal(pageTotal);

        return pageInfo;
    }
}
